<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="../react18/react.development.js"></script>
    <script src="../react18/react-dom.development.js"></script>
    <script src="../react18/babel.min.js"></script>
  </head>
  <body>
    <div id="app"></div>
    <script type="text/babel">
      class Child extends React.Component {
        state = {
          b: 2,
        };

        /* 
        static getDerivedStateFromProps:(了解)
          * 通过接受的props得到一个派生的state
          * 第一个参数是props 第二个参数是state
          * 函数返回的对象,最终会通过setState的方式合并到当前组件的state中
        
        */
        static getDerivedStateFromProps(props, state) {
          console.log(a, state);
          const { a } = props;
          return { myA: a };
        }

        render() {
          return (
            <div>
              <h2>Child组件</h2>
            </div>
          );
        }
      }

      class App extends React.Component {
        constructor() {
          super();
          console.log("-----constructor----");
        }
        render() {
          console.log("-----render-----");
          return (
            <div>
              <Child a="1" />
              <h2>App组件</h2>
            </div>
          );
        }

        componentDidMount() {
          console.log("-----componentDidMount-----");
        }
      }

      ReactDOM.createRoot(document.getElementById("app")).render(<App />);
    </script>
  </body>
</html>
